// pages/placeOrdInfor/orderInfor/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderInfor:'',
    isMore:false,
    animationData:{},
    rotateDown:{},
    rotateUp:{},
    orderId:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      orderId: options.id
    })
    this.getOrderInfor(options.id).then((re)=>{

    },(res)=>{
      
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var down = wx.createAnimation({ duration:0})
    var up = wx.createAnimation({ duration: 0 })
    down.rotate(90).step()
    up.rotate(180).step()
    this.setData({
      rotateDown: down.export(),
      rotateUp: up.export(),
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getOrderInfor(this.data.orderId).then((data) => {
      console.log(data)
      wx.stopPullDownRefresh();
    }, (res) => {

    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  /**
   * 请求订单信息
   */
  getOrderInfor:function(orderId){
    let _this = this
    let postUrl = wx.envConfig.host + '/order/findByOrder?cookiez=' + wx.getStorageSync('token')
    let porimsEvent
    let porimsReject
    wx.request({
      url: postUrl + '&params=' + JSON.stringify({
        "order_id": orderId
      }),
      method:'POST',
      success:(re)=>{
        if (re.data.error_code === 'Y10000'){
          re.data.datas.serviceInfo.detailed_1 = JSON.parse(re.data.datas.serviceInfo.detailed_1)
          porimsEvent(re.data.datas)
          this.setData({
            orderInfor: re.data.datas.serviceInfo
          })
        }else{
          porimsReject(re.data)
        }
      },
      fail:function(res){
        porimsReject(res)
      }
    })
    return new Promise((resolve, reject) => {
      porimsEvent = resolve
      porimsReject = reject
    })
  },
  /** 
   * 查看更多
   */
  seeMore:function(ev){
    var animation = wx.createAnimation({
      duration: 5000,
      timingFunction: 'ease',
    })
    if (this.data.isMore){
      animation.height(0).step()
    }else{
      animation.height('auto').step()
    }
    this.setData({
      isMore: !this.data.isMore,
      animationData: animation.export()
    })
  },
   /** 
   * 手术设计思路
   */
  goDesignThink:function(){
    wx.navigateTo({
      url: 'designThink?josn=' + this.data.orderInfor.ops_think_json
    })
  }
})